<template>
  <div class="app-container">

    <!-- 搜索工具栏 -->
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="260px">
      <el-row :gutter="10" class="mb8" v-show="false">
        <el-radio-group v-model="queryParams.enteState" size="mini" @change="handleQuery">
          <el-radio-button
            v-for="dict in enteStateOptions"
            :key="dict.dictValue"
            :label="dict.dictValue"
            :value="dict.dictValue"
          >{{dict.dictLabel}}</el-radio-button>
          <el-radio-button label="">全部</el-radio-button>
        </el-radio-group>
        <el-divider></el-divider>
      </el-row>
      <el-form-item label="企业ID" prop="enteId" v-show="false">
        <el-input
          v-model="queryParams.enteId"
          placeholder="请输入企业ID"
          clearable
          size="mini"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="企业名称" prop="enteTitle">
        <el-input
          v-model="queryParams.enteTitle"
          placeholder="请输入企业名称"
          clearable
          size="mini"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="统一社会信用代码" prop="enteCreditCode">
        <el-input
          v-model="queryParams.enteCreditCode"
          placeholder="请输入统一社会信用代码"
          clearable
          size="mini"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="邮箱" prop="enteEmail">
        <el-input
          v-model="queryParams.enteEmail"
          placeholder="请输入邮箱"
          clearable
          size="mini"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所在地区" prop="enteArea">
        <treeselect v-model="queryParams.enteArea" :options="areaOptions" :normalizer="areaNormalizer" placeholder="请选择所在地区" style="width: 220px"  :disable-branch-nodes="true" :default-expand-level="1"/>
      </el-form-item>
      <el-form-item label="国家级小巨人企业" prop="enteIsNationalGiant">
        <el-select v-model="queryParams.enteIsNationalGiant" placeholder="请选择" clearable size="mini" style="width: 80px">
          <el-option
            v-for="dict in enteIsNationalGiantOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="省级专精特新企业" prop="enteIsProvinceSpecial">
        <el-select v-model="queryParams.enteIsProvinceSpecial" placeholder="请选择" clearable size="mini" style="width: 80px">
          <el-option
            v-for="dict in enteIsProvinceSpecialOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="国家级小型微型企业创业创新示范基地" prop="enteIsNationalInnovateExampleBase">
        <el-select v-model="queryParams.enteIsNationalInnovateExampleBase" placeholder="请选择是否国家级小型微型企业创业创新示范基地" clearable size="small" style="width: 80px">
          <el-option
            v-for="dict in enteIsNationalInnovateExampleBaseOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="省级小型微型企业创业创新示范基地" prop="enteIsProvinceInnovateExampleBase">
        <el-select v-model="queryParams.enteIsProvinceInnovateExampleBase" placeholder="请选择" clearable size="mini" style="width: 80px">
          <el-option
            v-for="dict in enteIsProvinceInnovateExampleBaseOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="国家级中小企业公共服务示范平台" prop="enteIsNationalPublicExamplePlatform">
        <el-select v-model="queryParams.enteIsNationalPublicExamplePlatform" placeholder="请选择" clearable size="mini" style="width: 80px">
          <el-option
            v-for="dict in enteIsNationalPublicExamplePlatformOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="省级中小企业公共服务示范平台" prop="enteIsProvincePublicExamplePlatform">
        <el-select v-model="queryParams.enteIsProvincePublicExamplePlatform" placeholder="请选择" clearable size="mini" style="width: 80px">
          <el-option
            v-for="dict in enteIsProvincePublicExamplePlatformOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="上市公司" prop="enteIsIpo">
        <el-select v-model="queryParams.enteIsIpo" placeholder="请选择" clearable size="mini" style="width: 80px">
          <el-option
            v-for="dict in enteIsIpoOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 功能按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:enterprise:add']"
          v-show="handleAddShow"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:enterprise:edit']"
          v-show="handleUpdateShow"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-upload"
          size="mini"
          :disabled="multiple"
          @click="handleSubmit"
          v-hasPermi="['business:enterprise:submit']"
          v-show="handleSubmitShow"
        >提交</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:enterprise:remove']"
          v-show="handleDeleteShow"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['business:enterprise:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="enterpriseList" @selection-change="handleSelectionChange" :header-cell-style="{'text-align':'center'}">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column
        label="序号"
        type="index"
        min-width="20%"
        align="center">
        <template slot-scope="scope">
          <span>{{(queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1}}</span>
        </template>
      </el-table-column>
      <el-table-column label="企业ID" align="center" prop="enteId" />
      <el-table-column label="企业名称" align="left" prop="enteTitle" width="260"/>
      <el-table-column label="统一社会信用代码" align="left" prop="enteCreditCode" width="150"/>
      <el-table-column label="邮箱" align="center" prop="enteEmail" width="150"/>
      <el-table-column label="所在地区" align="center" prop="enteArea" :formatter="enteAreaFormat"/>
      <el-table-column label="国家级小巨人企业" align="center" prop="enteIsNationalGiant" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enteIsNationalGiant"/>
        </template>
      </el-table-column>
      <el-table-column label="省级专精特新企业" align="center" prop="enteIsProvinceSpecial" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enteIsProvinceSpecial"/>
        </template>
      </el-table-column>
      <el-table-column label="国家级小型微型企业创业创新示范基地" align="center" prop="enteIsNationalInnovateExampleBase" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enteIsNationalInnovateExampleBase"/>
        </template>
      </el-table-column>
      <el-table-column label="省级小型微型企业创业创新示范基地" align="center" prop="enteIsProvinceInnovateExampleBase" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enteIsProvinceInnovateExampleBase"/>
        </template>
      </el-table-column>
      <el-table-column label="国家级中小企业公共服务示范平台" align="center" prop="enteIsNationalPublicExamplePlatform" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enteIsNationalPublicExamplePlatform"/>
        </template>
      </el-table-column>
      <el-table-column label="省级中小企业公共服务示范平台" align="center" prop="enteIsProvincePublicExamplePlatform" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enteIsProvincePublicExamplePlatform"/>
        </template>
      </el-table-column>
      <el-table-column label="上市公司" align="center" prop="enteIsIpo" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.enteIsIpo"/>
        </template>
      </el-table-column>
      <el-table-column label="审批状态" align="center" prop="enteState" min-width="50%">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_verify_type" :value="scope.row.enteState"/>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="enteCreateTime" width="120">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.enteCreateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="创建用户" align="center" prop="enteCreateBy" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleShow(scope.row)"
            v-hasPermi="['business:enterprise:query']"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:enterprise:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-upload"
            @click="handleSubmit(scope.row)"
            v-hasPermi="['business:enterprise:submit']"
            v-show="handleSubmitShow"
          >提交</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:enterprise:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleApproval(scope.row)"
            v-hasPermi="['business:enterprise:pass']"
            v-show="handleApprovalShow"
          >审批</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleApprovalBack(scope.row)"
            v-hasPermi="['business:enterprise:pass']"
            v-show="handleApprovalBackShow"
          >反审批</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 翻页控件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改企业对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="260px">
        <el-form-item label="企业ID" prop="enteId" v-show="false">
          <el-input v-model="form.enteId" placeholder="请输入企业ID" />
        </el-form-item>
        <el-form-item label="企业名称" prop="enteTitle">
          <el-input v-model="form.enteTitle" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="enteCreditCode">
          <el-input v-model="form.enteCreditCode" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="营业执照" prop="enteBusinessLicense">
          <imageUpload v-model="form.enteBusinessLicense"/>
        </el-form-item>
        <el-form-item label="邮箱" prop="enteEmail">
          <el-input v-model="form.enteEmail" placeholder="请输入邮箱"/>
        </el-form-item>
        <el-form-item label="所在地区" prop="enteArea">
          <treeselect v-model="form.enteArea" :options="areaOptions" :normalizer="areaNormalizer" placeholder="请选择所在地区"  :disable-branch-nodes="true"  :default-expand-level="1"/>
        </el-form-item>
        <el-form-item label="地区说明" prop="enteAreaInfo">
          <el-input v-model="form.enteAreaInfo" placeholder="请输入地区说明" />
        </el-form-item>
        <el-form-item label="国家级小巨人企业" prop="enteIsNationalGiant">
          <el-radio-group v-model="form.enteIsNationalGiant">
            <el-radio
              v-for="dict in enteIsNationalGiantOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="省级专精特新企业" prop="enteIsProvinceSpecial">
          <el-radio-group v-model="form.enteIsProvinceSpecial">
            <el-radio
              v-for="dict in enteIsProvinceSpecialOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="国家级小型微型企业创业创新示范基地" prop="enteIsNationalInnovateExampleBase">
          <el-radio-group v-model="form.enteIsNationalInnovateExampleBase">
            <el-radio
              v-for="dict in enteIsNationalInnovateExampleBaseOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="省级小型微型企业创业创新示范基地" prop="enteIsProvinceInnovateExampleBase">
          <el-radio-group v-model="form.enteIsProvinceInnovateExampleBase">
            <el-radio
              v-for="dict in enteIsProvinceInnovateExampleBaseOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="国家级中小企业公共服务示范平台" prop="enteIsNationalPublicExamplePlatform">
          <el-radio-group v-model="form.enteIsNationalPublicExamplePlatform">
            <el-radio
              v-for="dict in enteIsNationalPublicExamplePlatformOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="省级中小企业公共服务示范平台" prop="enteIsProvincePublicExamplePlatform">
          <el-radio-group v-model="form.enteIsProvincePublicExamplePlatform">
            <el-radio
              v-for="dict in enteIsProvincePublicExamplePlatformOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="上市公司" prop="enteIsIpo">
          <el-radio-group v-model="form.enteIsIpo">
            <el-radio
              v-for="dict in enteIsIpoOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="enteRemark">
          <el-input v-model="form.enteRemark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 查看或审阅企业对话框 -->
    <el-dialog :title="title" :visible.sync="showopen" width="600px" append-to-body>
      <el-form ref="form" :model="showForm" label-width="250px">
        <el-form-item label="企业ID" prop="enteId" v-show="false">
          <el-input v-model="showForm.enteId" placeholder="请输入企业ID" />
        </el-form-item>
        <el-form-item label="企业名称" prop="enteTitle">
          <el-input v-model="showForm.enteTitle" placeholder="请输入企业名称" />
        </el-form-item>
        <el-form-item label="统一社会信用代码" prop="enteCreditCode">
          <el-input v-model="showForm.enteCreditCode" placeholder="请输入统一社会信用代码" />
        </el-form-item>
        <el-form-item label="营业执照" prop="enteBusinessLicense">
          <imageUpload v-model="showForm.enteBusinessLicense"/>
        </el-form-item>
        <el-form-item label="邮箱" prop="enteEmail">
          <el-input v-model="showForm.enteEmail" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="所在地区" prop="enteArea">
          <treeselect v-model="showForm.enteArea" :options="areaOptions" :normalizer="areaNormalizer" placeholder="请选择所在地区" disabled/>
        </el-form-item>
        <el-form-item label="地区说明" prop="enteAreaInfo">
          <el-input v-model="showForm.enteAreaInfo" placeholder="请输入地区说明" readonly/>
        </el-form-item>
        <el-form-item label="国家级小巨人企业">
          <el-radio-group v-model="showForm.enteIsNationalGiant" disabled>
            <el-radio
              v-for="dict in enteIsNationalGiantOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="省级专精特新企业">
          <el-radio-group v-model="showForm.enteIsProvinceSpecial" disabled>
            <el-radio
              v-for="dict in enteIsProvinceSpecialOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="国家级小型微型企业创业创新示范基地">
          <el-radio-group v-model="showForm.enteIsNationalInnovateExampleBase">
            <el-radio
              v-for="dict in enteIsNationalInnovateExampleBaseOptions"
              :key="dict.dictValue"
              disabled
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="省级小型微型企业创业创新示范基地">
          <el-radio-group v-model="showForm.enteIsProvinceInnovateExampleBase" disabled>
            <el-radio
              v-for="dict in enteIsProvinceInnovateExampleBaseOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="国家级中小企业公共服务示范平台">
          <el-radio-group v-model="showForm.enteIsNationalPublicExamplePlatform" disabled>
            <el-radio
              v-for="dict in enteIsNationalPublicExamplePlatformOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="省级中小企业公共服务示范平台">
          <el-radio-group v-model="showForm.enteIsProvincePublicExamplePlatform" disabled>
            <el-radio
              v-for="dict in enteIsProvincePublicExamplePlatformOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="上市公司">
          <el-radio-group v-model="showForm.enteIsIpo" disabled>
            <el-radio
              v-for="dict in enteIsIpoOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
            >{{dict.dictLabel}}</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="备注" prop="enteRemark">
          <el-input v-model="showForm.enteRemark" type="textarea" placeholder="请输入内容" readonly/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handlePass" id="passButton" v-show="passButtonShow">审批通过</el-button>
        <el-button type="danger" @click="handleBack" id="backButton" v-show="backButtonShow">退回</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import { listEnterprise, getEnterprise, submitEnterprise, delEnterprise, addEnterprise, updateEnterprise, exportEnterprise, passEnterprise, backEnterprise } from "@/api/business/enterprise";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
import {listArea} from "@/api/business/area";

export default {
  name: "Enterprise",
  dicts: ['sys_yes_no', 'sys_verify_type'],
  components: {
    Treeselect
  },
  data() {
    const enteIsNationalGiantCheck = (rule, value, callback) => {
      if (value == 0) {
        callback(new Error("请选择是否国家级小巨人企业"));
      } else {
        callback();
      }
    };
    const enteIsProvinceSpecialCheck = (rule, value, callback) => {
      if (value == 0) {
        callback(new Error("请选择是否省级专精特新企业"));
      } else {
        callback();
      }
    };
    const enteIsNationalInnovateExampleBaseCheck = (rule, value, callback) => {
      if (value == 0) {
        callback(new Error("请选择是否国家级小微企业创业创新示范基地"));
      } else {
        callback();
      }
    };
    const enteIsProvinceInnovateExampleBaseCheck = (rule, value, callback) => {
      if (value == 0) {
        callback(new Error("请选择是否省级小微企业创业创新示范基地"));
      } else {
        callback();
      }
    };
    const enteIsNationalPublicExamplePlatformCheck = (rule, value, callback) => {
      if (value == 0) {
        callback(new Error("请选择是否国家级中小企业公共服务示范平台"));
      } else {
        callback();
      }
    };
    const enteIsProvincePublicExamplePlatformCheck = (rule, value, callback) => {
      if (value == 0) {
        callback(new Error("请选择是否省级中小企业公共服务示范平台"));
      } else {
        callback();
      }
    };
    const enteIsIpoCheck = (rule, value, callback) => {
      if (value == 0) {
        callback(new Error("请选择是否上市公司"));
      } else {
        callback();
      }
    };
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 地区选项
      areaArrrayOptions: [],
      // 地区树选项
      areaOptions: [],
      // 显示搜索条件
      showSearch: true,
      // 列表状态
      listState: "",
      // 总条数
      total: 0,
      // 企业表格数据
      enterpriseList: [],
      // 弹出层标题
      title: "",
      // 列表页面的功能按钮是否显示的变量
      handleAddShow: true,
      handleUpdateShow: true,
      handleDeleteShow: true,
      handleSubmitShow: true,
      handleApprovalShow: true,
      handleApprovalBackShow: true,
      // 审核对话框的审核、反审核按钮是否显示变量
      passButtonShow: true,
      backButtonShow: true,
      // 是否显示新增或修改企业信息的弹出层
      open: false,
      // 是否显示新增或修改企业信息的弹出层
      showopen: false,
      // 国家级小巨人企业字典
      enteIsNationalGiantOptions: [],
      // 省级专精特新企业字典
      enteIsProvinceSpecialOptions: [],
      // 国家级小型微型企业创业创新示范基地字典
      enteIsNationalInnovateExampleBaseOptions: [],
      // 省级小型微型企业创业创新示范基地字典
      enteIsProvinceInnovateExampleBaseOptions: [],
      // 国家中小企业公共服务示范平台字典
      enteIsNationalPublicExamplePlatformOptions: [],
      // 省级中小企业公共服务示范平台字典
      enteIsProvincePublicExamplePlatformOptions: [],
      // 上市公司字典
      enteIsIpoOptions: [],
      // 审批状态字典
      enteStateOptions: [],
      // 创建时间时间范围
      daterangeEnteCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enteId: null,
        enteTitle: null,
        enteCreditCode: null,
        enteEmail: null,
        enteArea: null,
        enteIsNationalGiant: null,
        enteIsProvinceSpecial: null,
        enteIsNationalInnovateExampleBase: null,
        enteIsProvinceInnovateExampleBase: null,
        enteIsNationalPublicExamplePlatform: null,
        enteIsProvincePublicExamplePlatform: null,
        enteIsIpo: null,
        enteCreateId: null,
        enteState: null,
        enteCreateTime: null,
        enteCreateBy: null,
        enteUpdateBy: null,
        enteApproveBy: null
      },
      // 表单参数
      form: {},
      // 查看表单参数
      showForm: {},
      // 表单校验
      rules: {
        enteTitle: [
          { required: true, message: "企业名称不能为空", trigger: "blur" }
        ],
        enteCreditCode: [
          { required: true, message: "统一社会信用代码不能为空", trigger: "blur" }
        ],
        enteBusinessLicense: [
          { required: true, message: "请上传营业执照", trigger: "blur" }
        ],
        enteEmail: [
          { required: true, message: "邮箱不能为空", trigger: "blur" },
          {
            type: "email",
            message: "'请输入正确的邮箱地址",
            trigger: ["blur", "change"]
          }
        ],
        enteArea: [
          { required: true, message: "所在地区不能为空", trigger: "change" }
        ],
        enteIsNationalGiant: [
          { required: true, message: "请选择是否国家级小巨人企业", trigger: "blur" },
          { required: true, validator: enteIsNationalGiantCheck, trigger: "blur" }
        ],
        enteIsProvinceSpecial: [
          { required: true, message: "请选择是否省级专精特新企业", trigger: "blur" },
          { required: true, validator: enteIsProvinceSpecialCheck, trigger: "blur" }
        ],
        enteIsNationalInnovateExampleBase: [
          { required: true, message: "请选择是否国家级小微企业创业创新示范基地", trigger: "blur" },
          { required: true, validator: enteIsNationalInnovateExampleBaseCheck, trigger: "blur" }
        ],
        enteIsProvinceInnovateExampleBase: [
          { required: true, message: "请选择是否省级小微企业创业创新示范基地", trigger: "blur" },
          { required: true, validator: enteIsProvinceInnovateExampleBaseCheck, trigger: "blur" }
        ],
        enteIsNationalPublicExamplePlatform: [
          { required: true, message: "请选择是否国家级中小企业公共服务示范平台", trigger: "blur" },
          { required: true, validator: enteIsNationalPublicExamplePlatformCheck, trigger: "blur" }
        ],
        enteIsProvincePublicExamplePlatform: [
          { required: true, message: "请选择是否省级中小企业公共服务示范平台", trigger: "blur" },
          { required: true, validator: enteIsProvincePublicExamplePlatformCheck, trigger: "blur" }
        ],
        enteIsIpo: [
          { required: true, message: "请选择是否上市公司", trigger: "blur" },
          { required: true, validator: enteIsIpoCheck, trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getAreaTreeselect();
    this.getDicts("sys_yes_no").then(response => {
      this.enteIsNationalGiantOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.enteIsProvinceSpecialOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.enteIsNationalInnovateExampleBaseOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.enteIsProvinceInnovateExampleBaseOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.enteIsNationalPublicExamplePlatformOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.enteIsProvincePublicExamplePlatformOptions = response.data;
    });
    this.getDicts("sys_yes_no").then(response => {
      this.enteIsIpoOptions = response.data;
    });
    this.getDicts("sys_verify_type").then(response => {
      this.enteStateOptions = response.data;
    });
    this.getAreas().then(response => {
      this.areaArrrayOptions = response.data;
    });
  },
  methods: {
    /** 查询企业列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeEnteCreateTime && '' != this.daterangeEnteCreateTime) {
        this.queryParams.params["beginEnteCreateTime"] = this.daterangeEnteCreateTime[0];
        this.queryParams.params["endEnteCreateTime"] = this.daterangeEnteCreateTime[1];
      }
      const listState = this.queryParams.enteState;
      listEnterprise(this.queryParams).then(response => {
        // 列表中每一行的按钮是否显示的变量
        this.handleAddShow = false;
        this.handleUpdateShow = false;
        this.handleDeleteShow = false;
        this.handleSubmitShow = false;
        this.handleApprovalShow = false;
        this.handleApprovalBackShow = false;

        if(listState == null || listState == "")
        {
          this.queryParams.enteState = "";
          this.handleAddShow = true;
            this.handleUpdateShow = true;
            this.handleDeleteShow = true;
        } else if(listState == "initial")
        {
          this.handleAddShow = true;
          this.handleUpdateShow = true;
          this.handleDeleteShow = true;
          this.handleSubmitShow = true;
        } else if(listState == "approvalback")
        {
          this.handleUpdateShow = true;
          this.handleDeleteShow = true;
          this.handleSubmitShow = true;
        } else if(listState == "approval")
        {
          this.handleApprovalShow = true;
        } else if(listState == "definite")
        {
          this.handleApprovalBackShow = true;
        }

        this.enterpriseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 转换地区数据结构 */
    areaNormalizer(node) {
      if (node.children && !node.children.length) {
        delete node.children;
      }
      return {
        id: node.areaId,
        label: node.areaTitle,
        children: node.children
      };
    },
    /** 查询地区下拉树结构 */
    getAreaTreeselect() {
      listArea().then(response => {
        this.areaOptions = [];
        const data = { areaId: 0, areaTitle: '顶级节点', children: [] };
        data.children = this.handleTree(response.data, "areaId", "areaFatherId");
        this.areaOptions.push(data);
      });
    },
    /** 创建列表中地区名字的字典翻译 */
    enteAreaFormat(row, column) {
      return this.selectAreaLabel(this.areaArrrayOptions, row.enteArea)
    },
    // 国家级小巨人企业字典翻译
    enteIsNationalGiantFormat(row, column) {
      return this.selectDictLabel(this.enteIsNationalGiantOptions, row.enteIsNationalGiant);
    },
    // 省级专精特新企业字典翻译
    enteIsProvinceSpecialFormat(row, column) {
      return this.selectDictLabel(this.enteIsProvinceSpecialOptions, row.enteIsProvinceSpecial);
    },
    // 是否国家级小型微型企业创业创新示范基地字典翻译
    enteIsNationalInnovateExampleBaseFormat(row, column) {
      return this.selectDictLabel(this.enteIsNationalInnovateExampleBaseOptions, row.enteIsNationalInnovateExampleBase);
    },
    // 省级小型微型企业创业创新示范基地字典翻译
    enteIsProvinceInnovateExampleBaseFormat(row, column) {
      return this.selectDictLabel(this.enteIsProvinceInnovateExampleBaseOptions, row.enteIsProvinceInnovateExampleBase);
    },
    // 国家中小企业公共服务示范平台字典翻译
    enteIsNationalPublicExamplePlatformFormat(row, column) {
      return this.selectDictLabel(this.enteIsNationalPublicExamplePlatformOptions, row.enteIsNationalPublicExamplePlatform);
    },
    // 省级中小企业公共服务示范平台字典翻译
    enteIsProvincePublicExamplePlatformFormat(row, column) {
      return this.selectDictLabel(this.enteIsProvincePublicExamplePlatformOptions, row.enteIsProvincePublicExamplePlatform);
    },
    // 上市公司字典翻译
    enteIsIpoFormat(row, column) {
      return this.selectDictLabel(this.enteIsIpoOptions, row.enteIsIpo);
    },
    // 审批状态字典翻译
    enteStateFormat(row, column) {
      return this.selectDictLabel(this.enteStateOptions, row.enteState);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.showopen = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        enteId: null,
        enteTitle: null,
        enteCreditCode: null,
        enteBusinessLicense: null,
        enteEmail: null,
        enteArea: null,
        enteAreaInfo: null,
        enteIsNationalGiant: "0",
        enteIsProvinceSpecial: "0",
        enteIsNationalInnovateExampleBase: "0",
        enteIsProvinceInnovateExampleBase: "0",
        enteIsNationalPublicExamplePlatform: "0",
        enteIsProvincePublicExamplePlatform: "0",
        enteIsIpo: "0",
        enteRemark: null,
        enteCreateId: null,
        enteState: null,
        enteCreateTime: null,
        enteUpdateId: null,
        enteCreateBy: null,
        enteUpdateTime: null,
        enteApproveId: null,
        enteApproveTime: null,
        enteUpdateBy: null,
        enteApproveBy: null
      };
      this.showForm = {
        enteId: null,
        enteTitle: null,
        enteCreditCode: null,
        enteBusinessLicense: null,
        enteEmail: null,
        enteArea: null,
        enteAreaInfo: null,
        enteIsNationalGiant: "0",
        enteIsProvinceSpecial: "0",
        enteIsNationalInnovateExampleBase: "0",
        enteIsProvinceInnovateExampleBase: "0",
        enteIsNationalPublicExamplePlatform: "0",
        enteIsProvincePublicExamplePlatform: "0",
        enteIsIpo: "0",
        enteRemark: null,
        enteCreateId: null,
        enteState: null,
        enteCreateTime: null,
        enteUpdateId: null,
        enteCreateBy: null,
        enteUpdateTime: null,
        enteApproveId: null,
        enteApproveTime: null,
        enteUpdateBy: null,
        enteApproveBy: null
      };
      this.resetForm("form");
      this.resetForm("showForm");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeEnteCreateTime = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.enteId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getAreaTreeselect();
      this.open = true;
      this.title = "添加企业";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.getAreaTreeselect();
      const enteId = row.enteId || this.ids
      getEnterprise(enteId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改企业";
      });
    },
    /** 查看按钮操作 */
    handleShow(row) {
      this.reset();
      this.getAreaTreeselect();
      const enteId = row.enteId || this.ids
      getEnterprise(enteId).then(response => {
        this.showForm = response.data;
        this.showopen = true;
        this.title = "查看企业";
        this.passButtonShow = false;
        this.backButtonShow = false;
      });
    },
    /** 进入审批对话框按钮操作 */
    handleApproval: function (row) {
      this.reset();
      this.getAreaTreeselect();
      const enteId = row.enteId || this.ids
      getEnterprise(enteId).then(response => {
        this.showForm = response.data;
        this.showopen = true;
        this.title = "审批企业";
        this.passButtonShow = true;
        this.backButtonShow = true;
      });
    },
    /** 进入反审批对话框按钮操作 */
    handleApprovalBack: function (row) {
      this.reset();
      this.getAreaTreeselect();
      const enteId = row.enteId || this.ids
      getEnterprise(enteId).then(response => {
        this.showForm = response.data;
        this.showopen = true;
        this.title = "反审批企业";
        this.passButtonShow = false;
        this.backButtonShow = true;
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.enteId != null) {
            updateEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addEnterprise(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 提交供审批按钮操作 */
    handleSubmit(row) {
      const enteIds = row.enteId || this.ids;
      this.$confirm('是否确认将企业编号为"' + enteIds + '"的数据项提交审批?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info"
      }).then(function() {
        return submitEnterprise(enteIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("提交成功");
      }).catch(() => {});
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const enteIds = row.enteId || this.ids;
      this.$confirm('是否确认删除企业编号为"' + enteIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return delEnterprise(enteIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('business/enterprise/export', {
        ...this.queryParams
      }, `enterprise_${new Date().getTime()}.xlsx`)
    },
    /** 审批通过按钮 */
    handlePass() {
      const enteIds = this.showForm.enteId || this.ids;
      this.$confirm('是否确认审核通过企业编号为"' + enteIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        passEnterprise(enteIds).then(response => {
          this.$modal.msgSuccess("审批通过成功");
          this.showopen = false;
          this.getList();
        });
      }).then(response => {
      }).catch(() => {});
    },
    /** 反审批退回按钮 */
    handleBack() {
      const enteIds = this.showForm.enteId || this.ids;
      this.$confirm('是否确认反审批退回企业编号为"' + enteIds + '"的数据项?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        backEnterprise(enteIds).then(response => {
          this.$modal.msgSuccess("反审批退回成功");
          this.showopen = false;
          this.getList();
        });
      }).then(response => {
      }).catch(() => {});
    }
  }
};
</script>
